home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9871 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: peacock.tcinc.com!news
  2. From: Christopher Sweeney <csweeney>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: protected access to grandparent class
  5. Date: 4 Mar 1996 22:29:52 GMT
  6. Organization: Tele-Communications, Inc.
  7. Message-ID: <4hfqt0$2a8@peacock.tcinc.com>
  8. References: <Dnqstp.Jo9@uns.bris.ac.uk>
  9. NNTP-Posting-Host: aitsun24.tcinc.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.12 (X11; I; SunOS 5.4 sun4m)
  14. X-URL: news:Dnqstp.Jo9@uns.bris.ac.uk
  15.  
  16. nathan@pact.srf.ac.uk (Nathan Sidwell) wrote:
  17. >The following class heirarchy is giving me grief.
  18. >-snip
  19. >class A {
  20. >protected:
  21. >  int member;
  22. >  void func(A){};
  23. >};
  24. >
  25. >class B : protected A {
  26. >protected:
  27. >  void func(B arg) {
  28. >    A::func(A(arg));      // ok
  29. >  };
  30. >};
  31. >
  32. >class C : protected B {
  33. >protected:
  34. >  void func(C arg) {
  35. >    A::func(A(arg));      // failed
  36. >  };
  37. >};
  38. >-snip
  39. >
  40. >As far as I can determined the line marked 'failed' is class C's equivalent
  41. >of the line marked 'ok'. However, g++ 2.7.2 says,
  42. >
  43. >foo.cc: In method `void C::func(class C)':
  44. >foo.cc:17: fields of `const A' are inaccessible in `C' due to private inheritance
  45. >foo.cc:5: in passing argument 1 of `A::A(const A &)'
  46. >foo.cc:17: in conversion to type `A'
  47. >
  48. >and cfront says,
  49. >
  50. >"foo.cc", line 17: error: cast: C* -> base A*; protected base class
  51. >"foo.cc", line 17: error:  object or pointer missing for A::func() of type  void A::(A)
  52. >
  53. >however, SGI CC accepts the code.
  54. >
  55. >I can't see anything in 11.2 of the draft standard which indicates that the rule
  56. >it describes cannot be applied recursively -- it doesn't describe any other
  57. >method for determining the access to grandparent members.
  58. >
  59. >Is my understanding incomplete or are g++ and cfront confused?
  60. >
  61. The ARM does not specify behaviour for "protected" base classes, only private
  62. and public.
  63. The "Draft Standard" includes use of protected base classes.  It appears that
  64. the versions
  65. of g++ and cfront you are using are equating protected base class with private
  66. base class.
  67.  
  68. From my reading of the draft standard the SGI compiler is correct.
  69. C.
  70.  
  71.